package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.MydetailResult;
import com.zhouyibike.uu.utils.TextUtils;

import java.util.List;

/**
 * Created by cc on 2017/5/3.
 */

public class MydetailAdapter extends BaseAdapter {
    private Context context;
    private List<MydetailResult.DataBean> list;

    public MydetailAdapter(Context context, List<MydetailResult.DataBean> list) {
        this.context = context;
        this.list = list;
    }
    public  void setList(List<MydetailResult.DataBean> list){
        this.list = list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.item_mydetail,null);
        TextView tv_type= (TextView) convertView.findViewById(R.id.tv_detail_type);
        TextView tv_time= (TextView) convertView.findViewById(R.id.tv_mydetail_time);
        TextView tv_miney= (TextView) convertView.findViewById(R.id.tv_detail_money);
//        tv_detail_money
        if (TextUtils.isNullorEmpty(list.get(position).getAmount()))
        {}else{
            if (list.get(position).getAmount().startsWith("-"))
            {
                tv_miney.setTextColor(context.getResources().getColor(R.color.jianhao));
            }else{
                tv_miney.setTextColor(context.getResources().getColor(R.color.color_normal));
            }
        }
        tv_time.setText(list.get(position).getCreateTime());
        tv_miney.setText(list.get(position).getAmount());
        tv_type.setText(list.get(position).getOrderType());
        return convertView;
    }
}
